package com.max.back.demo.service.impl;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.max.back.demo.dao.DoctorDao;
import com.max.back.demo.entity.Doctor;
import com.max.back.demo.service.DoctorSer;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * DoctorSerImpl
 */
@Service
public class DoctorSerImpl extends ServiceImpl<DoctorDao, Doctor> implements DoctorSer {
    @Override
    public List<Doctor> finddoctor(String id, String sex, String dept) {
        return baseMapper.finddoctor(id,sex,dept);
    }

    @Override
    public boolean checkandinsert(Doctor doctor) {
        Map<String, String> codemap =baseMapper.maxcode();
        if(codemap==null) {
            doctor.setId("2022001");
        } else {
            String codeMaxNum = codemap.get("maxid").substring(5);
            System.out.println(codeMaxNum);
            Integer stuCodeMaxNumInt = Integer.parseInt(codeMaxNum);
            String lastFix = NumberUtil.decimalFormat("000", ++stuCodeMaxNumInt);
            doctor.setId("2022" + lastFix);
        }
        return save(doctor);
    }
}
